import 'package:cbec_app/components/base/base_image.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

//赠品弹窗
class GiftsPopup extends StatelessWidget {
  
  ///赠品列表
  final List sendList;

  const GiftsPopup({super.key,required this.sendList});

  
  @override
  Widget build(BuildContext context) {
    return Container(
        width: 375.w,
        height: MediaQuery.of(context).size.height * 0.5,
        decoration:  BoxDecoration(
            color: Tools.fromHex("#F8F8F8"),
            borderRadius: const BorderRadius.only(
                topLeft: Radius.circular(8), topRight: Radius.circular(8))),
                child: Container(
                  padding: EdgeInsets.only(top: 10.w),
                  child: Stack(
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.end,
                            children: [
                              SizedBox(width: 18.w),
                              Expanded(
                                child: Align(
                                alignment: Alignment.center,
                                child: Text("赠品",style: setTextStyle(15, FontWeight.w700, Tools.fromHex("#333333"))),
                              )),
                              BaseInteractive(
                                childWidget: const Icon(Icons.close),
                                onClick: () {
                                  Get.back();
                                },
                              ),
                              SizedBox(width: 18.w)
                            ],
                          ),
                          Container(
                            height: 320.w,
                            padding: EdgeInsets.fromLTRB(8.w, 10.w, 8.w, 10.w),
                            child: SingleChildScrollView(
                            child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children:sendList.map((item) => giftItem(item)).toList()
                            ),
                          ),
                          ),
                          
                        ],
                      ),
                      Positioned(
                          bottom: MediaQuery.of(context).padding.bottom,
                          child: Container(
                            padding: EdgeInsets.fromLTRB(18.w, 5.w, 18.w, 5.w),
                            width: 375.w,
                            color: Colors.white,
                            child: solidButton('确定', () {
                            Get.back();
                          }),
                          ))
                    ],
                  ),
                ));
  }

}

///赠品ITEM
Widget giftItem(Map<String,dynamic> item){
  return Container(
      margin: EdgeInsets.only(bottom: 10.w),
      padding: EdgeInsets.all(10.w),
      decoration: border_radis(Colors.white),
      child: Row(
        children: [
          //头像
          Stack(
            children: [
              BaseImage(url:item['img']?? "https://gw.alicdn.com/bao/uploaded/i4/1107882860/O1CN01FP34Eo1WzvNtT5xur_!!1107882860.jpg_320x320q90.jpg_.webp", width: 100.w,height: 100.w,borderRadius: BorderRadius.circular(10.w)),
              //赠品标记
              Positioned(
                top: 1,
                left: 1,
                child: SizedBox(
                width: 100.w,
                height: 100.w,
                child: BaseImage(url: "gift_tag.png", width: 100.w,height: 100.w),
              )),
            ],
          ),
          SizedBox(width: 10.w),
          //右侧
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                goodsTypeTag("保税"),
                SizedBox(height: 10.w),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    SizedBox(
                      width: 160.w,
                      child: Text(item['goodsName'].toString(),style: setTextStyle(14, FontWeight.w300, Tools.fromHex("#333333")),overflow: TextOverflow.ellipsis,maxLines: 2),
                    ),
                    
                    Column(
                      children: [
                        Row(
                          children: [
                            Text("￥",style: setTextStyle(10, FontWeight.w500, Tools.fromHex("#333333"))),
                            Text(item['goodsPrice'].toString(),style: setTextStyle(15, FontWeight.w300, Tools.fromHex("#333333"))),
                          ],
                        ),
                        Text("共${item['send'].toString()}件",style: setTextStyle(11, FontWeight.w500, Tools.fromHex("#999999")))
                      ],
                    )
                  ],
                )
              ],
            ))
        ],
      ),
    ); 
}



///唤起赠品弹窗
void showGiftsPopup(List sendList){
  showCupertinoModalPopup(context: Get.context!, builder: (context){
    return GiftsPopup(sendList: sendList,);
  });
}